package com.bawei.service.impl;

import com.bawei.mapper.ExamineMapper;
import com.bawei.mapper.OvertimeMapper;
import com.bawei.mapper.UserInfoMapper;
import com.bawei.pojo.*;
import com.bawei.service.ExamineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
@Transactional
public class ExamineServiceImpl implements ExamineService{
    @Autowired
    private ExamineMapper examineMapper;
    @Autowired
    private OvertimeMapper overtimeMapper;
    @Autowired
    private UserInfoMapper userInfoMapper;
    @Override
    public List<Examine> list() {
        ExamineExample example=new ExamineExample();
        ExamineExample.Criteria criteria = example.createCriteria();
        criteria.andStatusEqualTo(0);
        return examineMapper.selectByExample(example);
    }

    @Override
    public Overtime selectUid(String s) {
        return overtimeMapper.selectByPrimaryKey(s);
    }

    @Override
    public UserInfo getrealName(String userId) {
        return userInfoMapper.selectByPrimaryKey(userId);
    }

    @Override
    public Overtime detail(String id) {
        return overtimeMapper.selectByPrimaryKey(id);
    }

    @Override
    public Examine selectExamineById(String id) {
        return examineMapper.selectByPrimaryKey(id);
    }

    @Override
    public void updateStatus(String id, Integer status, String realName) {
        ExamineExample example=new ExamineExample();
        ExamineExample.Criteria criteria = example.createCriteria();
        criteria.andTIdEqualTo(id);
        List<Examine> list = examineMapper.selectByExample(example);
        for (Examine examine : list) {
            examine.setStatus(status);
            examine.setExamineTime(new Date());
            examine.setExamineUser(realName);
            examineMapper.updateByPrimaryKeySelective(examine);
            Overtime overtime = overtimeMapper.selectByPrimaryKey(examine.gettId());
            overtime.setStatus(status);
            overtimeMapper.updateByPrimaryKeySelective(overtime);
        }
    }
}
